package com.ywjh.inter.service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.ywjh.inter.conn.DBConnection;
import com.ywjh.inter.dao.InstitutionDAO;
import com.ywjh.inter.entity.InstitutionEntity;

public class InstService {
	private static InstService instance;
	private InstitutionDAO institutionDAO;

	public static InstService getInstance() {
		if (instance == null) {
			instance = new InstService();
			instance.institutionDAO = new InstitutionDAO();
		}
		return instance;
	}

	public InstitutionEntity findById(int id) {
		Connection conn = null;
		InstitutionEntity institutionEntity = null;
		try {
			conn = DBConnection.getDBConnection();
			institutionEntity = institutionDAO.findById(conn, id);
		} catch (ClassNotFoundException | SQLException e) {
			e.printStackTrace();
		} finally {
			DBConnection.close(conn);
		}
		return institutionEntity;
	}

	public List<InstitutionEntity> listByPid(int inst_id) {
		Connection conn = null;
		List<InstitutionEntity> list=null;
		try {
			conn = DBConnection.getDBConnection();
			list = institutionDAO.findByPid(conn, inst_id);
		} catch (ClassNotFoundException | SQLException e) {
			e.printStackTrace();
		} finally {
			DBConnection.close(conn);
		}
		return list;
	}
}
